<!--
 * @Author: zhangweinan
 * @Date: 2023-01-13 15:38:58
 * @LastEditors: zhangweinan
 * @LastEditTime: 2023-02-03 16:41:38
 * @Description: file content
 * @FilePath: \front-end-of-task-center\src\views\dashboard\PieChartNew.vue
-->
<template>
  <div :class="className" :style="{ height: height, width: width }" />
</template>

<script>
// import echarts from "echarts";
// require("echarts/theme/macarons"); // echarts theme
import resize from "./mixins/resize";

export default {
  mixins: [resize],
  props: {
    name: { type: String, default: "pie图表" },
    className: {
      type: String,
      default: "chart",
    },
    width: {
      type: String,
      default: "100%",
    },
    height: {
      type: String,
      default: "300px",
    },
    chartData: {
      type: Object,
      required: true,
    },
    pieTotal: {
      type: Number,
      require: true,
    },
  },
  data() {
    return {
      chart: null,
    };
  },
  watch: {
    chartData: {
      deep: true,
      handler(val) {
        this.initChart(val);
      },
    },
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart();
    });
  },
  beforeDestroy() {
    if (!this.chart) {
      return;
    }
    this.chart.dispose();
    this.chart = null;
  },
  methods: {
    initChart({ yAxios, xAxios } = {}) {
      this.chart = this.$echarts.init(this.$el, "macarons");

      this.chart.setOption({
        color: [
          "#4877EE",
          "#48EEAF",
          "#642DD7",
          "#EE4869",
          "#CCCCCC",
          "#FF9393",
        ],
        tooltip: {
          trigger: "item",
          formatter: "{a} <br/>{b} : {c} ({d}%)",
        },
        legend: {
          bottom: "2%",
          data: xAxios,
        },
        series: [
          {
            type: "pie",
            zlevel: 1,
            silent: true,
            radius: ["75%", "75.6%"],
            hoverAnimation: false,
            color: "#E6ECFC",
            label: {
              normal: {
                show: false,
              },
            },
            labelLine: {
              normal: {
                show: false,
              },
            },
            data: [1],
          },
          {
            name: this.name,
            type: "pie",
            radius: ["60%", "70%"],
            data: yAxios,
            label: {
              normal: {
                show: true,
                position: "center",
                color: "#4c4a4a",
                formatter:
                  "{total|" +
                  this.pieTotal +
                  "}" +
                  "\n\r" +
                  "{active|流程总数}",
                rich: {
                  total: {
                    fontSize: 26,
                    fontFamily: "微软雅黑",
                    color: "#4877EE",
                    fontWeight: 500,
                  },
                  active: {
                    fontFamily: "微软雅黑",
                    fontSize: 16,
                    color: "#4877EE",
                    lineHeight: 30,
                    fontWeight: 500,
                  },
                },
              },
              emphasis: {
                //中间文字显示
                show: true,
              },
            },
            animationEasing: "cubicInOut",
            animationDuration: 2600,
          },
        ],
      });
    },
  },
};
</script>
